<?php
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];
include_once $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();

$mode = $_GET["mode"];
if($mode == "update"){
	$getListFood= $managerIUDS->queryData("*", "food", " WHERE food_id = ".$_GET["food_id"], "1", "");
	$speciesDataList = $managerIUDS->queryData(" species_id,species_name ","species","","2","");
}else{
	$speciesDataList = $managerIUDS->queryData(" species_id,species_name ","species","","2","");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Food Detail :.</title>
<?php
require_once($rootPath . "/" . $contextPath . "/includes/css_inc.php");
require_once($rootPath . "/" . $contextPath . "/includes/js_inc.php");
?>
<script type="text/javascript">
			$(document).ready(function(){ 
				$("#save_data").click(function(){
					var result = true;
					if($("#food_name").val()=="" || $("#food_name").val()==null){
						alert("กรุณากรอกชื่ออาหาร");
						$("#food_name").focus(); 
						result = false
					}else if($("#price").val()=="" || $("#price").val()==null){
						alert("กรุณากรอกราคาอาหาร");
						$("#price").focus(); 
						result = false
					}else if($("#species_id").val()=="0" || $("#species_id").val()==null){
						alert("กรุณาเลือกประเภทของสัตว์เลี้ยง");
						$("#species_id").focus(); 
						result = false
					}
					if(result){
						$("#frm1").submit();
					}
				});
				$(function() {
					$( "#combobox" ).combobox();
				});
			}); 
		</script>
</head>
<body>
<center>
<form name="frm1" id="frm1" action="../actions/food_action.php" method="post">
<table border="0" width="75%">
	<thead class="ui-widget">
		<tr class="ui-widget-header">
			<th colspan="2" align="left">&nbsp;&nbsp;&nbsp;รายละเอียดอาหาร</th>
		</tr>
	</thead>
	<tbody class="ui-widget-content">
		<tr>
			<td align="right">ชื่ออาหาร : </td>
			<td><input type="text" name="food_name" id="food_name" value="<?=$getListFood["food_name"]?>"></td>
		</tr>
		<tr>
			<td align="right">รายละเอียดอาหาร : </td>
			<td>
				<textarea name="food_detail" id="food_detail" cols="21"	rows="5"><?=$getListFood["food_detail"]?></textarea>
			</td>
		</tr>
		<tr>
			<td align="right">ราคา : </td>
			<td>
				<input name="price" id="price" onkeypress="return numbersOnly(event, false);" value="<?=$getListFood["price"]?>">
			</td>
		</tr>
		<tr>
			<td align="right">อาหารสำหรับสัตว์เลี้ยงน้ำหนัก : </td>
			<td>
				<input type="radio" name="pet_weight" id="pet_weight" value="L" checked="checked">น้อยกว่า 25
				<input type="radio" name="pet_weight" id="pet_weight" value="M"
				<?php
					if($getListFood["pet_weight"] =="M"){
						echo 'checked="checked"';
					} 
				?>
				>มากกว่า 25 
			</td>
		</tr>
		<tr>
			<td align="right">ประเภท : </td>
			<td>
			<select name="species_id" id="species_id">	
				<option value="0">---- เลือก ----</option>
				<?php 
						foreach($speciesDataList as $value){
					?>
						<option value="<?=$value["species_id"]?>"
						<?php 
						if($value["species_id"]==$getListFood["species_id"]){
							echo 'selected="selected"'; 
						}
						?>
						><?=$value["species_name"]?></option>
					<?php 
						}
					//}
					?>	
			</select>
			</td>
		</tr>
		<tr>
			<td colspan="2" align="center">
			<input type="button" name="save_data" id="save_data" value="บันทึก">
			<input type="button" value="ยกเลิก"	onclick="window.location='food_main.php';"></td>
		</tr>
	</tbody>
</table>
<input type="hidden" id="mode" name="mode" value=<?=$mode?>>
<input	type="hidden" id="food_id" name="food_id" value="<?=$_GET["food_id"]?>">
</form>
</center>
</body>
</html>